package com.chenxi.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.Principal;

/**
 * Created by BEYOND on 2017/7/13.
 */
@Controller
@RequestMapping(value = "/userApi/")
@Slf4j
public class UserController {

    //@Autowired
    //private UserDetailsManager userDetailsManager;
    @RequestMapping(value = "/me")
    @ResponseBody
    public Principal getUser(Principal principal){
        User activeUser = (User) ((Authentication) principal).getPrincipal();
        log.info(activeUser.getUsername());
        return principal;
    }

    @ResponseBody
    @RequestMapping(value="saveUser")
    public String saveUser(User user){
       // userDetailsManager.createUser(user);
        return "wsss";
    }

}
